package com.example.toutiao.ui.main.act


import android.content.Intent
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.toutiao.R
import com.example.toutiao.base.BaseActivity
import com.example.toutiao.ui.main.adpater.AddressAdapter
import com.example.toutiao.ui.main.model.AddressModel
import com.example.toutiao.ui.main.presenter.AddressPresenter
import com.example.toutiao.ui.main.view.AddressView
import com.example.toutiao.ui.user.EvtMsgModel
import kotlinx.android.synthetic.main.activity_address.*

class AddressActivity : BaseActivity<AddressView, AddressPresenter>(), AddressView {
    override fun getLayoutId(): Int = R.layout.activity_address
    override fun initView() {
        icon_back.setOnClickListener { finish() }
    }

    override fun initData() {
        getPresenter()!!.getProvince()
    }

    override fun createPresenter(): AddressPresenter = AddressPresenter()

    override fun isRegister(): Boolean = true

    override fun <T> setData(data: T) {
        val mList = data as MutableList<AddressModel>
        rv_address_list.layoutManager = LinearLayoutManager(this)
        val adapter = AddressAdapter(mList)
        rv_address_list.adapter = adapter
        adapter.setOnClickListener(object:AddressAdapter.OnClickListener{
            override fun OnClick(title: String) {
                val intent= Intent(this@AddressActivity,CityActivity::class.java)
                intent.putExtra("province",title)
                startActivity(intent)
            }

        })
    }

    override fun setError(err: String) {

    }

    override fun getMessage(message: EvtMsgModel<*>) {
        super.getMessage(message)
        if(message!=null){
            if(message.code==301){
                finish()
            }
        }
    }

}